package com.hsgene.common.util.collection;

import java.util.HashSet;
import java.util.Set;

/**
 * 集合操作工具
 *
 * @author wangbing
 * @version 1.0, 2018/7/14
 */
public class SetUtils {

    /**
     * 交集
     */
    public static <T> Set<T> intersect(Set<T> src, Set<T> dest) {
        Set<T> set = new HashSet<>(src.size());
        set.addAll(src);
        set.retainAll(dest);
        return set;
    }

    /**
     * 并集
     */
    public static <T> Set<T> union(Set<T> src, Set<T> dest) {
        Set<T> set = new HashSet<>(src.size());
        set.addAll(src);
        set.addAll(dest);
        return set;
    }

    /**
     * 差集
     */
    public static <T> Set<T> diff(Set<T> src, Set<T> dest) {
        Set<T> set = new HashSet<>(src.size());
        set.addAll(src);
        set.removeAll(dest);
        return set;
    }
}
